package com.success.hrm.fallback;


import com.success.hrm.feignclients.RedisFeignClient;
import com.success.hrm.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RedisFeignClientFallbackFactory implements FallbackFactory<RedisFeignClient> {

    @Override
    public RedisFeignClient create(Throwable throwable) {
        return new RedisFeignClient() {
            //托底方法
            @Override
            public AjaxResult set(String key, String value) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("Redis服务不可用["+throwable.getMessage()+"]");
            }

            //托底方法
            @Override
            public AjaxResult get(String key) {
                //查询数据中的数据，返回
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("Redis服务不可用["+throwable.getMessage()+"]");
            }
        };
    }

}
